Advertisement
Guest User

codeigniter form_helper overrides

a guest
Dec 1st, 2011
1,120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. /**
  4. * Form Value
  5. *
  6. * Grabs a value from the POST array for the specified field so you can
  7. * re-populate an input field or textarea.  If Form Validation
  8. * is active it retrieves the info from the validation class
  9. *
  10. * @access   public
  11. * @param   string
  12. * @return   mixed
  13. */
  14. if (!function_exists('set_value')) {
  15.  
  16.     function set_value($field = '', $default = '') {
  17.         $OBJ = & _get_validation_object();
  18.  
  19.         if ($OBJ === TRUE && isset($OBJ->_field_data[$field])) {
  20.             return form_prep($OBJ->set_value($field, $default));
  21.         } else {
  22.             if (!isset($_POST[$field])) {
  23.                 return $default;
  24.             }
  25.  
  26.             return form_prep($_POST[$field]);
  27.         }
  28.     }
  29.  
  30. }
  31.  
  32. if (!function_exists('set_checkbox')) {
  33.  
  34.     function set_checkbox($field = '', $value = '', $default = '') {
  35.         $OBJ = & _get_validation_object();
  36.  
  37.         if ($OBJ === TRUE && isset($OBJ->_field_data[$field])) {
  38.             return form_prep($OBJ->set_checkbox($field, $value, $default));
  39.         } else {
  40.             if (!isset($_POST[$field])) {
  41.                 return '';
  42.             }
  43.             else{
  44.                 if($_POST[$field] == $value)
  45.                 {
  46.                     return 'checked=\'checked\'';
  47.                 }
  48.             }
  49.         }
  50.     }
  51.  
  52. }
  53.  
  54. /* End of file MY_form_helper.php */
  55. /* Location: ./application/core/MY_form_helper.php */  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement